/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Action;

import ActionForm.RegisterForm;
import Model.CusModel;
import bean.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author cpn02
 */
public class RegisterAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
       // return super.execute(mapping, form, request, response); forward lại url request tới nó
        RegisterForm cus = (RegisterForm)form;
        if(CusModel.isExitsUserName(cus.getUserName()))
        {
            String mess = "User name da duoc su dung";
            request.setAttribute("failRegister", mess);
            return mapping.findForward("fail");
        }
        else
        {
            CusModel.Register(cus.getUserName(), cus.getPassw(), cus.getEmail(), cus.getPhone(), cus.getAddress(),cus.getGender());
            request.getSession().setAttribute("customer", CusModel.getCustomer(cus.getUserName(), cus.getPassw()));
            return mapping.findForward("success");
        }
    }

}
